package com.newtouch.bxzs.business.whiteList.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.newtouch.bxzs.business.enclosure.controller.EnclosureController;
import com.newtouch.bxzs.business.whiteList.model.WhiteListBO;
import com.newtouch.bxzs.business.whiteList.model.WhiteListVO;
import com.newtouch.bxzs.business.whiteList.service.WhiteListService;
import com.newtouch.bxzs.common.base.model.WhiteList;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 白名单
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021年8月18日</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author Amour
 *
 * @version 1.0.0
 * @since 1.0.0
 */

@RestController
@RequestMapping(value = "/white")
@SuppressWarnings("unchecked")
public class WhiteListController {

    /** 静态变量：系统日志 */
    private static final Log logger = LogFactory.getLog(EnclosureController.class);

    @Autowired
    private WhiteListService whiteListService;

    @GetMapping(value = "/getList")
    @ApiOperation(value = "查询白名单信息")
    public BaseResponse<List<WhiteListBO>> getList(){
        return RespGenerator.returnOK(whiteListService.getWhiteList1());
    }

    @PostMapping(value = "/getWhiteList")
    @ApiOperation(value = "查询白名单信息")
    public BaseResponse<IPage<WhiteListBO>> getWhiteList(@RequestBody WhiteListVO whiteListVO){
        logger.info("展示白名单列表");
        return RespGenerator.returnOK(whiteListService.getWhiteList(whiteListVO));
    }

    @PostMapping(value = "/deleteWhite")
    @ApiOperation(value = "删除白名单")
    public BaseResponse<Integer> deleteWhite(@RequestBody @ApiParam(name = "whiteListIds", value = "白名单id集合", required = true) List<String> whiteListIds) {
        logger.info("删除白名单");
        return RespGenerator.returnOK(whiteListService.updateDelState(whiteListIds));
    }

    @PostMapping("/modifyWhite")
    @ApiOperation(value = "修改白名单信息")
    public BaseResponse<Integer> modifyWhiteList(@RequestBody WhiteList whiteList) {
        logger.info("增加/修改白名单信息");
        return RespGenerator.returnOK(whiteListService.modifyWhiteListUser(whiteList));
    }
}
